<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        //寻找数组 出现次数最多的元素，并返回出现的次数
        var arr = [12, 54, 8, 32, 7, 8, 8, 8, 7];
        function findMax(arr) {
            var count = 0,
                max = 1,
                curValue = arr[0];
            for (var i = 0; i < arr.length; i++) {
                var cur = arr[i];
                for (var j = i; j < arr.length; j++) {
                    if (cur == arr[j]) {
                        count++;
                    }
                }
                if (count > max) {
                    curValue = cur;
                    max = count;
                }
                count = 0;
            }
            console.log(arr);
            console.log("最多出现的元素是:", curValue, "出现了" + max + "次");
        }
        findMax(arr);





    </script>
</body>

</html>